# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=aspell
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.60.8
pkgrel=2
pkgdesc="A spell checker designed to eventually replace Ispell (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="http://aspell.net/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread-git"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-gettext")
options=('strip' 'staticlibs')
source=("https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.gz"{,.sig}
        0001-use-namespace.mingw.patch
        0002-printf.mingw.patch
        0003-no-undefined-on.mingw.patch
        0004-reloc.mingw.patch
        0005-w32-home.all.patch
        0006-abort.mingw.patch
        0007-fix-including-langinfo.patch)
sha256sums=('f9b77e515334a751b2e60daab5db23499e26c9209f5e7b7443b05235ad0226f2'
            'SKIP'
            '903c798d1afa40b4e36ec0d4c1b82a967d217507f03742c3c480568cc527e429'
            '9d2640cd250d8a6f5ce8d59080b13edd5ecfa53c0eb1628f22cc93a8c2397109'
            '88ec0327160f362eb896158e443485cd549ede3aaa1d51ca642cf22ed2feee19'
            'e08e48c75af27ba63a4ea15f5cdee15d6f5f018e926cc5d5082ed96cc09070e2'
            '8a937dd625aefb8ece3553eb5b1aca888856298d01ae9d8da14c3d574d52871d'
            'd5e69f1c352e4d01d23297c06269f5430e584cf2535329e9c934d2209a43cc0d'
            '8ff2cfc11963d0738c435a27c42e2f28dabf473270310f98ef6252a9707d4501')
validpgpkeys=('31A768B0808E4BA619B48F81B6D9D0CC38B327D7') # Kevin Atkinson <kevina@gnu.org>

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-use-namespace.mingw.patch
  patch -p1 -i ${srcdir}/0002-printf.mingw.patch
  patch -p1 -i ${srcdir}/0003-no-undefined-on.mingw.patch
  patch -p1 -i ${srcdir}/0004-reloc.mingw.patch
  patch -p1 -i ${srcdir}/0005-w32-home.all.patch
  patch -p1 -i ${srcdir}/0006-abort.mingw.patch
  patch -p1 -i ${srcdir}/0007-fix-including-langinfo.patch

  autoreconf -fi
}

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  cp -rf "${srcdir}"/${_realname}-${pkgver} "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  CPPFLAGS+=" -DENABLE_W32_PREFIX=1"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-static \
    --enable-shared \
    --disable-curses

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make -j1 DESTDIR="${pkgdir}" install
}
